﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace MethodWorx.Core.Extensions
{
    public static class TypeExtensions
    {
        public static object InvokeOnInterface(this Type src, Type interfaceType, string name, BindingFlags flags, Binder binder, object target, object[] args)
        {
            return interfaceType.InvokeMember(name, flags, binder, target, args);
        }

        public static PropertyInfo [] GetInterfaceProperties(this Type src)
        {
            List<PropertyInfo> properties = new List<PropertyInfo>();

            if (src.IsInterface)
            {
                foreach (PropertyInfo pi in src.GetProperties())
                {
                    properties.Add(pi);
                }

            }

            foreach (Type type in src.GetInterfaces())
            {
                foreach (PropertyInfo pi in type.GetProperties())
                {
                    properties.Add(pi);
                }
            }


            return properties.ToArray();
        }
    }
}
